package server;

import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @author KEM
 *
 */
public class Server {

    private int port = 0;
    private ServerSocket server;

    public Server(int port) {
        this.port = port;
    }

    public void startS() {
        try {
            Robot robot = null;
            Rectangle rectangle = null;
            
                initServer();
                while (true) {
                    Socket client = server.accept();
                    System.out.println("Client just connected...");
                    //lấy mội trường đồ họa trong máy.lấy kích cỡ màn hình mặc định
                    GraphicsDevice graphicDevice = GraphicsEnvironment
                            .getLocalGraphicsEnvironment().getDefaultScreenDevice();
                    //lấy kích cỡ màn hình
                    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
                    //cái này thì chưa hiểu lắm, chắc là lấy khung
                    rectangle = new Rectangle(screenSize);
                    //khởi tạo lớp robot
                    robot = new Robot(graphicDevice);
                    ScreenSender screenSender = new ScreenSender(client, robot, rectangle);
                    CommandReceiver commandReceiver = new CommandReceiver(client, robot);
                }
        } catch (AWTException ex) {
            Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
        }
           
        
       
    }

    private void initServer() throws IOException {
        server = new ServerSocket(port);
    }
    
    
}
